<template>
  <div class="sidebar">
    <el-menu
      class="sidebar-el-menu"
      :collapse="collapse"
      background-color="#253041"
      text-color="#ffffff"
      active-text-color="#409eff"
      unique-opened
      router
    >
      <template v-for="item in items">
        <template>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from "../assets/js/bus";

export default {
  data() {
    return {
      collapse: false,
      items: [
        {
          icon: "el-icon-document",
          index: "/Home/Index",
          title: "系统首页",
        },
        {
          icon: "el-icon-document",
          index: "/Home/User",
          title: "用户管理",
        },
        {
          icon: "el-icon-document",
          index: "/Home/Topic",
          title: "论坛管理",
        },
        {
          icon: "el-icon-document",
          index: "/Home/Announce",
          title: "公告管理",
        },
        {
          icon: "el-icon-document",
          index: "/Home/Help",
          title: "帮助管理",
        },
      ],
    };
  },
  computed: {},
  created() {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    bus.$on("collapse", (msg) => {
      this.collapse = msg;
    });
  },
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  background-color: #334256;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 150px;
}
.sidebar > ul {
  height: 100%;
}
</style>
